<template>
  <!--footer-->
  <footer>
    <ul class="up">
      <li>
        <img :src="item.img1" alt="" class="put">
        <div class="jieshao">
          <span>{{item.name}}</span>
          <span class="price">￥{{item.newprice}}</span>
        </div>
        <div class="quxiao">
          <i class="iconfont icon-cuowu"></i>
        </div>
      </li>
      <li>
        <div class="xuanqu">
          <span class="yanse">颜色</span>
          <div class="yangshi" >
            <span v-for="(n,index) in item.color" @click="change(index)" :class="{'changecolor':!index}" >{{n}}</span>
          </div>
        </div>
      </li>
      <li class="shuliang">
        <div>
          <span>数量</span>
          <div class="jiajian">
            <span @click="subs">-</span>
            <span class="num">{{num}}</span>
            <span @click="adds">+</span>
          </div>
        </div>
      </li>
    </ul>
    <div class="b_bottom">
      <div class="g_left">
        <a href="javascript:;" @click="entry()">
          <i class="iconfont icon-gouwuche"></i>
          <span>购物车</span>
        </a>
      </div>
      <div class="g_right">
        <div class="enjoy">
          <a href="javascript:;" @click="send(item)">加入购物车</a>
        </div>
        <div><a href="#">立即购买</a></div>
      </div>
    </div>
  </footer>
</template>
<script type="text/ecmascript-6">
  import  vue from "vue";
    export default {
      props:["item"],
      mounted:function(){
          $(".quxiao").click(function(){
            $(".up").toggle();
          });
      },
      data(){
        return{
          num:1,
          isShow:false,
        }
      },
      methods: {
        adds: function () {
          this.num++;
        },
        subs: function () {
          if (this.num <= 1) {
            this.num = 1
          } else {
            this.num--;
          }
        },
        send: function (item) {
          if ($(".up").is(":hidden")) {
            $(".up").css("display",'block');
            console.log("不发送");
          } else {
            console.log("发送");
            this.$http.post('http://localhost:3000/shopcar',{
              name: item.name,
              goodsid: item.goodsid,
              storename: item.storename,
              img1: item.img1,
              newprice: item.newprice,
              oldprice: item.oldprice,
              icon:item.icon,
              color:item.color,
              colorimg:item.colorimg,
              num:item.num,
            }, {
              emulateJSON: true//将request body以application/x-www-form-urlencoded发送
            }, {
              headers: {
                'Content-Type': 'application/x-www-form-urlencoded',//设置HTTP请求头
              },
            }).then((res) => {
              console.log("join");
            });
            $(".up").css("display",'none');
            $(".fu").show();
            $(".fu").html("商品加入成功");
            $(".fu").delay(1000).fadeOut("slow");
          }
        },
        change: function (idx) {
          var el = event.currentTarget;
          $(el).siblings("span").removeClass('changecolor');
          $(el).addClass('changecolor');
          var path = this.item.colorimg[idx];
          $(".put").attr('src', path);
        },
        entry: function () {
          this.$router.push("/Shoppingcar");
        },
      },
    }
</script>
<style scoped lang="scss">
  //footer
  footer{
    display:flex;
    flex-direction: column;
    font-size: 14px;
  }
  .g_left{
    width:30%;
    text-align: center;
    padding-top: 0.1rem;
  }
  .g_left span{
    display: block;
    color:black;
  }
  .g_left a{
    position:relative;
  }
  .g_left .icon-gouwuche{
    color: black;
    font-size:30px;
  }
  .g_left .num{
    width: 0.2rem;
    height: 0.2rem;
    position: absolute;
    background: #ef145a;
    top: -57px;
    border-radius: 50%;
    right: -25px;
    color: white;
  }
  .g_right{
    width:70%;
    display:flex;
  }
  .g_right div{
    width:50%;
    text-align: center;
    line-height: 0.6rem;
    background:black;
  }
  .g_right div a{
    color: white;
  }
  .g_right div:nth-child(1){
    background: #c3af97;
  }
  .b_bottom{
    display: flex;
    border-top:1px solid #dddddd;
  }
  footer>ul>li{
    padding: 0.15rem;
    display: flex;
    padding-bottom: 0.3rem;
  }
  footer>ul>li:nth-child(1){
    border-bottom: 1px solid #dddddd;
  }
  footer>ul>li:nth-child(2){
    display: flex;
    flex-direction: column;
    font-size:18px;
    font-weight:bold;
    font-family: monospace;
  }
  footer>ul>li>img{
    width: 1rem;
    height: 1rem;
    padding: 0.1rem;
    border: 1px solid #f0f0f0;
    margin-top: -0.2rem;
    z-index: 999;
    background: white;
  }
  .jieshao {
    display: flex;
    flex-direction: column;
    width: 50%;
    margin-top: 0.15rem;
    margin-left: 0.1rem;
  }
  .jieshao span:nth-child(1){
    font-weight: bold;
    font-size:14px;
  }
  .price{
    font-weight: bold;
    font-size:18px;
    color: #ed145b;
    margin-top: 0.1rem;
  }
  .quxiao{
    border: 1px solid black;
    border-radius: 50%;
    width: 0.15rem;
    height: 0.15rem;
    text-align: center;
    line-height: 0.1rem;
    margin-top: 0.15rem;
    margin-left: 0.1rem;
  }
  .quxiao .iconfont{
    font-size:8px;
  }
  .yangshi{
    padding-top:0.2rem;
    font-size: 14px;
  }
  .yangshi>span{
    padding:0.1rem;
    border:1px solid #f0f0f0;
  }
  .changecolor{
    background:#ed145b;
    color:white;
  }
  .xuanqu{
    padding:0.2rem 0;
    border-bottom:1px solid #dddddd;
  }
  .shuliang{
    padding-top:0!important;
    font-size: 18px;
    font-family: monospace;
    font-weight: bold;
  }
  .jiajian{
    padding-top:0.2rem;
    display: flex;
    margin-top: 0.17rem;
  }
  .jiajian span {
    padding: 0.05rem 0.2rem;
    border: 1px solid gray;
  }
  .num{
    color: #ed145b;
  }
  .up{
    display: none;
  }
</style>
